package com.book.dao;

import com.book.entity.Book;
import com.book.entity.Lend;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface BookMapper {
    @Results({
            @Result(column = "l_id",property = "lID"),
            @Result(column = "b_id",property = "bID"),
            @Result(column = "b_name",property = "bName"),
            @Result(column = "l_time",property = "lDate"),
            @Result(column = "s_name",property = "sName"),
            @Result(column = "s_id",property = "sID"),
    })
    @Select("select * from lend, student, book where lend.b_id = book.b_id and student.s_id = lend.s_id")
    List<Lend> getLendList();

    //删除借阅信息
    @Delete("delete from lend where l_id = #{l_id}")
    void deleteLend(String l_id);

    //查询所有书本信息
    @Select("select * from book")
    List<Book> getBookList();

    //添加借书信息
    @Insert("insert into lend(s_id,b_id,l_time) values(#{s_id},#{b_id},NOW())")
    void addLend(@Param("s_id")int s_id,@Param("b_id") int b_id);

    //删除书本信息
    @Delete("delete from book where b_id = ${b_id}")
    void deleteBook(int b_id);

    //添加书籍信息
    @Insert("insert into book(b_name,b_price) values(#{b_name},#{b_price})")
    void addBook(@Param("b_name") String b_name,@Param("b_price") Double b_price);
}
